package com.brisk.web.controller.applet;

import com.ruoyi.applet.domain.AppletMedal;
import com.ruoyi.applet.service.IAppletMedalService;
import com.brisk.common.annotation.Log;
import com.brisk.common.core.controller.BaseController;
import com.brisk.common.core.domain.AjaxResult;
import com.brisk.common.core.page.TableDataInfo;
import com.brisk.common.enums.BusinessType;
import com.brisk.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * appletMedalController
 *
 * @author PENGFEIDENG
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/applet/appletMedal")
public class AppletMedalController extends BaseController {
    @Autowired
    private IAppletMedalService appletMedalService;

    /**
     * 查询appletMedal列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appletMedal:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletMedal appletMedal) {
        startPage();
        List<AppletMedal> list = appletMedalService.selectAppletMedalList(appletMedal);
        return getDataTable(list);
    }

    /**
     * 导出appletMedal列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appletMedal:export')")
    @Log(title = "appletMedal", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletMedal appletMedal) {
        List<AppletMedal> list = appletMedalService.selectAppletMedalList(appletMedal);
        ExcelUtil<AppletMedal> util = new ExcelUtil<AppletMedal>(AppletMedal.class);
        util.exportExcel(response, list, "appletMedal数据");
    }

    /**
     * 获取appletMedal详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:appletMedal:query')")
    @GetMapping(value = "/{medalId}")
    public AjaxResult getInfo(@PathVariable("medalId") Long medalId) {
        return AjaxResult.success(appletMedalService.selectAppletMedalByMedalId(medalId));
    }

    /**
     * 新增appletMedal
     */
    @PreAuthorize("@ss.hasPermi('applet:appletMedal:add')")
    @Log(title = "appletMedal", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletMedal appletMedal) {
        return toAjax(appletMedalService.insertAppletMedal(appletMedal));
    }

    /**
     * 修改appletMedal
     */
    @PreAuthorize("@ss.hasPermi('applet:appletMedal:edit')")
    @Log(title = "appletMedal", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletMedal appletMedal) {
        return toAjax(appletMedalService.updateAppletMedal(appletMedal));
    }

    /**
     * 删除appletMedal
     */
    @PreAuthorize("@ss.hasPermi('applet:appletMedal:remove')")
    @Log(title = "appletMedal", businessType = BusinessType.DELETE)
    @DeleteMapping("/{medalIds}")
    public AjaxResult remove(@PathVariable Long[] medalIds) {
        return toAjax(appletMedalService.deleteAppletMedalByMedalIds(medalIds));
    }
}
